# 建立config函数，配置app选项
import logging

from redis import StrictRedis


class Config(object):
    DEBUG = True
    # 配置mysql的链接
    """pip install flask-sqlalchemy
        pip install mysqlclient==1.3.12
        pip install flask-mysqldb 
        pip install mysql-connector"""

    # 配置mysql数据库时必须有这两行代码
    SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://root:lj521wei@127.0.0.1:3306/information_num_two"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 在请求结束的时候，如果指定此配置为True  那么SQLAlchemy 会自动执行一次 db.session.commit()操作
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True


    # redis设置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # 配置session
    SESSION_TYPE = "redis"
    SESSION_USE_SIGNER = True
    SESSION_PERMANENT = False
    PERMANENT_SESSION_LIFETIME = 86400*2
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT) # 此时初始化的这个StrictRedis是专门用于存储session的
    SECRET_KEY = "fajdklfjasdfjaskdjfla"   # 这个值是由  bytes.decode(base64.b64encode(os.urandom(48)))  生成的随机值

    # 设置日志等级
    LOG_LEVEL = logging.DEBUG

class DevelopmentConfig(Config):
    # 开发环境下的配置
    DEBUG = True

class ProductionConfig(Config):
    # 生产环境下的配置
    DEBUG = False

    LOG_LEVEL = logging.WARNING

config = {
    'dev': DevelopmentConfig,
    'pro': ProductionConfig
}